<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

return [
    'id' => 'app-api',
    'basePath' => dirname(__DIR__),
    'language' => 'zh-CN',
    'bootstrap' => ['log'],
    'controllerNamespace' => 'api\controllers',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-api',
        ],
        'formatter' => [
            'dateFormat' => 'yyyy-MM-dd',
            'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => 'CNY',
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'enableSession' => false,
            'loginUrl' => null,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => false,
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => ['v1/course','v1/catalog','v1/content','v1/study'],
                    'tokens' =>[
                        '{id}' => '<id:[a-zA-Z0-9-_]*>',//view操作可以识别字符串
                    ],
                    'extraPatterns' => [
                        'GET search' => 'search',
                    ],
                    'pluralize' => false, //禁用复数形式
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => ['v1/user','v1/classify','v1/select'],
                    'tokens' => [
                        '{id}' => '<id:\\d[\\d,]*>', //view操作只能识别数字
                    ],
                    'pluralize' => false, //禁用复数形式
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => ['v1/default'],
                    'extraPatterns' => [
                        'POST login' => 'login',
                        'POST signup' => 'signup',
                    ],
                    'pluralize' => false,
                ],
            ],
        ]
    ],
    'modules' => [
        'v1' => [
            'class' => 'api\modules\v1\Module',
        ],
        'v2' => [
            'class' => 'api\modules\v2\Module',
        ],
    ],
    'params' => $params,
];
